//
//  JLHttpManager.m
//  LIangeNews
//
//  Created by 孙金亮 on 16/2/4.
//  Copyright © 2016年 sun. All rights reserved.
//

#import "JLHttpManager.h"

@implementation JLHttpManager
static JLHttpManager * manager;
+(instancetype)shareManager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manager = [[self alloc]init];
        NSMutableSet * muSet = [NSMutableSet set];
        muSet.set = manager.responseSerializer.acceptableContentTypes;
        [muSet addObject:@"text/html"];
        manager.responseSerializer.acceptableContentTypes = muSet;
    });
    return manager;
    
}
-(NSURLSessionDataTask *)requestWithJLMethod:(JLRequestMethod)method urlString:(NSString *)urlString parameters:(id)parameters finished:(JLFinishedBlock)finished{
    NSURLSessionDataTask * session = nil;
    if (method == GET) {
      session = [manager GET:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            if (finished) finished(responseObject,nil);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            if (finished) finished(nil,error);
        }];
    }else if (method == POST){
      session =  [manager POST:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            if (finished) finished(responseObject,nil);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            if (finished) finished(nil,error);
        }];
    }
    return session;
}
@end
